package geom;


/**
 * This class represents an width by height area within some space.
 * 
 * @author Robert c. Duvall
 */
public class Dimension extends java.awt.geom.Dimension2D
{
    private double myWidth;
    private double myHeight;


    public Dimension ()
    {
        this(0, 0);
    }

    public Dimension (double size)
    {
        this(size, size);
    }

    public Dimension (double width, double height)
    {
        setSize(width, height);
    }

    public Dimension (Dimension other)
    {
        this(other.getWidth(), other.getHeight());
    }


    public double getWidth ()
    {
        return myWidth;
    }

    public double getHeight ()
    {
        return myHeight;
    }


    public boolean equals (Dimension other)
    {
        if (this == other)        return true;
        else if (other == null)   return false;
        else
        {
            return (getWidth() == other.getWidth()) &&
                   (getHeight() == other.getHeight());
        }
    }
    
    
    public void setSize (double width, double height)
    {
        myWidth = Math.max(0.001, width);
        myHeight = Math.max(0.001, height);
    }

    public String toString ()
    {
        return getClass().getName() + 
               "[w=" + getWidth() + ",h=" + getHeight() + "]";
    }
}
